package cn.hbu.zlfw.system.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.hbu.zlfw.annotation.OperatorLog;
import cn.hbu.zlfw.annotation.OperatorType;
import cn.hbu.zlfw.common.util.PageModel;
import cn.hbu.zlfw.common.util.SessionUtil;
import cn.hbu.zlfw.system.entity.AdminUser;
import cn.hbu.zlfw.system.service.AdminUserService;
/**
 * 
 *@ClassName:AdminUserController.java
 *@Description:  总管理员控制层:对总管理员信息进行处理
 *@Author:lxt<839376636@qq.com>
 *@Date:2017年10月6日下午6:45:26
 *@Version:1.1.0
 */
@Controller("adminUserController")
@RequestMapping("/adminUser")
public class AdminUserController {
	/**
	 * 日志
	 */
	public final Logger logger = LoggerFactory.getLogger(AdminUserController.class);
	
	@Autowired
	private AdminUserService adminUserService;
	
	/**
	 * 注入HttpServletRequest
	 */
	@Autowired  
	private HttpServletRequest request;

	@ResponseBody
	@OperatorLog(type=OperatorType.SELECT,description="查询用户信息")
	@RequestMapping("/findAdminUserList")
	public String findAdminUserList(@ModelAttribute PageModel pageModel,String userName) {
		List<String> userIds = new ArrayList<String>();
		userIds.add("1");
		userIds.add("2");
		userIds.add("3");
		userIds.add("4");
		userIds.add("5");
		pageModel = this.adminUserService.findAdminUserList(pageModel, userName,userIds);
		System.out.println("pageModel:"+pageModel);
		
		List<Object> list = pageModel.getList();
		list.forEach(l->{
			System.out.println((AdminUser)l);
		});
		return "success!";
	}
	
	@OperatorLog(type=OperatorType.OTHER,description="用户登录成功")
	@RequestMapping("/login")
	public String login(@ModelAttribute AdminUser adminUser) {
		
		//this.adminUserService.save(adminUser);
		request.getSession().setAttribute(SessionUtil.SESSION_USER_KEY, adminUser);
		return "forward:/WEB-INF/regist/regist.jsp";
	}
	
}
